#!/usr/bin/env node

console.log('test')

const inquirer = require('inquirer');
const path = require('path');
const fs = require('fs');
const ejs = require('ejs');

inquirer.prompt([
  {
    type: 'input',
    name: 'name',
    message: '输入项目名称'
  }
]).then(answers => {
  const tempDir = path.join(__dirname, 'templates');
  const targetDir = process.cwd();

  fs.readdir(tempDir, (err, files) => {
    if(err) throw err;
    files.forEach(file => {
      ejs.renderFile(path.join(tempDir, file), answers, (err, str) => {
        fs.writeFile(path.join(targetDir, file), str, (err) => {
          if(err) throw err;
          console.log(path.join(targetDir, file) + '写入成功！')
        })
      })
    })
  })
  // console.log(dir)
  
})